home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / graphics / scan.lzh / BIGSCAN.S < prev    next >
Text File  |  1991-05-26  |  7KB  |  230 lines

  1.          opt o+
  2.  
  3.         bra    start            ;Program start
  4.  
  5.         include    d:\devpac2\aes.s    ;Only AES macros
  6.  
  7. start:        clr.b    file_name        ;No file name
  8.         initacc                ;Init GEM
  9.         tst.w    appid            ;PRG or ACC ?
  10.         bne.s    inst_acc        ;Install ACC
  11.         bsr.s    main            ;Run PRG
  12.         clr.w    -(sp)            ;Term
  13.         trap    #1            ;Gemdos
  14.  
  15. inst_acc:    move.w    appid(pc),int_in    ;Our AES ID
  16.         move.l    #acc_name,addr_in    ;Our Desk name
  17.         aes    menu_register        ;Install ACC
  18. event_loop:    move.l    #msgbuff,addr_in    ;Set buffer
  19.         aes    evnt_mesag        ;Get event
  20.         cmpi.w    #40,msgbuff        ;ACC_open ?
  21.         bne.s    event_loop        ;No, wait
  22.         bsr.s    main            ;Yes, open acc
  23.         bra.s    event_loop        ;Wait for next time
  24.     
  25. main:        movem.l    d0-a6,-(sp)        ;Save all registers
  26.         move.w    #3,int_in        ;Disable Mouse
  27.         aes    wind_update
  28.  
  29.         lea    file_path(pc),a5    ;Adress of string
  30.         move.w    #$19,-(sp)        ;Get drive
  31.         trap    #1            ;Gemdos
  32.         addq.l    #2,sp
  33.         addq.w    #1,d0            ;Make 1-offset drive id
  34.         move.w    d0,-(sp)        ;Push on stack
  35.         addi.b    #64,d0            ;Make ASCII
  36.         move.b    d0,(a5)            ;Save in string
  37.         move.b    #':',1(a5)        ;Save ':' in string
  38.         pea    2(a5)            ;Buffer for dir-name
  39.         move.w    #$47,-(sp)        ;Get dir
  40.         trap    #1            ;Gemdos
  41.         addq.l    #8,sp
  42.         lea    (a5),a4            ;Start of text
  43. check_next:    tst.b    (a4)+            ;End of string ?
  44.         beq.s    end_str            ;Yes, stop scan
  45.         bra.s     check_next        ;Check next char
  46. end_str:    subq.l    #1,a4            ;One char back
  47.         lea    extension(pc),a5    ;Data adress
  48. move_char:    move.b    (a5),(a4)+        ;Move data
  49.         tst.b    (a5)+            ;Was it $00 ?
  50.         bne.s    move_char        ;No, next char
  51.  
  52.         move.l    #file_path,addr_in    ;Path for fsel
  53.         move.l    #file_name,addr_in+4    ;File name for fsel
  54.         move.l    #fsel_message,addr_in+8    ;Info message (>TOS 1.4)
  55.         aes    fsel_exinput        ;Extended file selector
  56.         tst.w    int_out+2        ;Cancel pressed ?
  57.         beq    abort_acc        ;Yes, abort
  58.         
  59.         dc.w    $A00A            ;Hide Mouse
  60.         clr.l    int_in            ;Just border, x=0
  61.         move.w    #19,int_in+4        ;Full size
  62.         move.w    #640,int_in+6        ;Full size
  63.         move.w  #381,int_in+8        ;Full size
  64.         aes    wind_create
  65.         move.w    int_out(pc),w_handle    ;Save handle
  66.         move.w    w_handle(pc),int_in    ;Window handle
  67.         aes    wind_open
  68.         
  69. scan_image:    clr.l    -(sp)            ;Super mode
  70.         move.w    #$20,-(sp)        ;Super
  71.         trap    #1            ;Gemdos
  72.         addq.l    #6,sp
  73.         move.l    d0,save_ssp        ;Save stack
  74.         
  75.         movea.l $44E.w,a0        ;Screen adress
  76.         adda.l    #19*80,a0        ;19 lines for menu
  77.         move.l    a0,a1            ;Copy of start
  78.         move.w    #7619,d7        ;Counter
  79. blank_screen:    move.l    #$FFFFFFFF,(a1)+    ;Black screen
  80.         dbf.w    d7,blank_screen        ;Next long
  81.  
  82.         moveq.l    #0,d4            ;For btst of scanline
  83.         moveq.l    #8,d5            ;For btst of roller
  84.         moveq.l    #1,d3            ;For btst of data
  85.         move.w    #761,d7            ;381 lines/screen
  86.  
  87.         lea    $FB0000,a1        ;Status & Roller pos
  88.         lea    $FB1000,a2        ;Data request
  89.         lea    $FB2001,a3        ;Data receive
  90.         lea    img_buffer(pc),a4    ;Data buffer
  91.  
  92.         move.b    #$13,$FFFFFC02.W    ;Shut off Keyboard
  93.         move.w    #$2700,sr        ;Interrupts off
  94.         tst.w    $FB4000            ;Scanner light on
  95.         
  96. scan_line:    moveq.l    #79,d6            ;80 bytes/line
  97.         move.w    #$80A0,(a4)+        ;160 bytes of data
  98. wait_roller:    move.w    (a1),d2            ;Get roller status
  99.         btst.l    d5,d2            ;Has roller moved
  100.         bne.s    wait_roller        ;No, wait for move
  101. get_blank:    tst.w    (a2)            :Ask for data
  102. wait_blank:    btst.b    d3,(a1)            ;Data ready ?
  103.         beq.s    wait_blank        ;No, wait for blank
  104.         btst.l    d4,d7            ;Odd or Even scanline ?
  105.         bne.s    scan_screen        ;Show data on screen
  106.  
  107.         move.w    #159,d6            ;160 bytes/scan line
  108. get_data2:    tst.w    (a2)            ;Ask for data
  109. wait_data2:    btst.b    d3,(a1)            ;Data ready ?
  110.         beq.s    wait_data2        ;No, wait for data
  111.         move.b    (a3),(a4)+        ;Move data to img-buffer
  112.         dbf.w    d6,get_data2        ;Ask for more data
  113.         dbf.w    d7,scan_line        ;Wait for next line
  114.         bra.s    end_scan        ;Scanning complete
  115.  
  116. scan_screen:    moveq.l    #79,d6            ;80 bytes on screen
  117. get_data:    tst.w    (a2)            ;Ask for data
  118. wait_data:    btst.b    d3,(a1)            ;Data ready ?
  119.         beq.s    wait_data        ;No, wait for data
  120.         move.b    (a3),(a0)+        ;Move data to screen
  121.         move.b    (a3),(a4)+        ;Move data to img-buffer
  122.         dbf.w    d6,get_data        ;Ask for more data
  123.         moveq.l    #79,d6            ;80 bytes right of screen
  124.         bra.s    get_data2        ;Get rest of data
  125.  
  126. end_scan:    tst.w    $FB3000            ;Scanner light off
  127.         move.w    #$2300,sr        ;Interrupts on
  128.         move.b    #$11,$FFFFFC02.W    ;Keyboard on again
  129.  
  130.         move.l  save_ssp(pc),-(sp)    ;User mode
  131.         move.w    #$20,-(sp)        ;Super
  132.         trap    #1            ;Gemdos
  133.         addq.l    #6,sp
  134.  
  135.         dc.w    $A009            ;Show mouse
  136.         move.w    #1,int_in        ;Default button
  137.         move.l    #alert,addr_in        ;Alert box text
  138.         aes    form_alert        ;Do alert box
  139.         dc.w    $A00A            ;Hide Mouse
  140.  
  141.         cmp.w    #1,int_out        ;Scan button ?
  142.         beq    scan_image        ;Yes, Again
  143.  
  144.         cmp.w    #2,int_out        ;Save button ?
  145.         bne    close_window        ;No, Close ACC
  146.  
  147.         lea    file_name(pc),a6    ;Start filename
  148. check_char:    cmp.b    #'.',(a6)        ;Found '.' ?
  149.         beq.s    name_ok            ;Yes, Name OK
  150.         tst.b    (a6)+            ;End of text ?
  151.         bne.s    check_char        ;No, Check next
  152.         subq.l    #1,a6            ;Yes, One char back
  153.         lea    extension+2(pc),a5    ;Data '.IMG'
  154. move_char2:    move.b    (a5),(a6)+        ;Move data
  155.         tst.b    (a5)+            ;Was it $00 ?
  156.         bne.s    move_char2        ;No, next char
  157.  
  158. name_ok:    lea    file_path(pc),a6    ;Path-name
  159.         clr.w    d0            ;Last '\' pos
  160.         clr.w    d1            ;Char counter
  161. check_slash:    cmp.b    #'\',(a6,d1.w)        ;Found new '\' ?
  162.         bne.s    check_end
  163.         move.w    d1,d0            ;Save last '\'
  164. check_end:    tst.b    (a6,d1.w)        ;End of text
  165.         beq.s    finished
  166.         addq.w    #1,d1            ;Next char
  167.         bra.s    check_slash
  168.  
  169. finished:    lea    file_name(pc),a5    ;Start filename
  170. move_name:    addq.w    #1,d0            ;Next char in path
  171.         move.b    (a5),(a6,d0.w)        ;Move after path
  172.         tst.b    (a5)+            ;End of name ?
  173.         bne.s    move_name        ;No, next char
  174.  
  175.         clr.w    -(sp)            ;Read and Write        
  176.         move.l    a6,-(sp)        ;Full name of file
  177.         move.w    #$3C,-(sp)        ;Create file
  178.         trap    #1            ;Gemdos
  179.         addq.l    #8,sp
  180.         tst.w    d0            ;Error ?
  181.         bmi.s    close_window        ;Yes, Abort
  182.         move.w    d0,handle        ;Save file handle
  183.         
  184.         pea    img_header(pc)        ;Start of img-file
  185.         move.l    #16,-(sp)        ;Number of bytes
  186.         move.w    handle(pc),-(sp)    ;File handle
  187.         move.w    #$40,-(sp)        ;Write data
  188.         trap    #1            ;Gemdos
  189.         lea    12(sp),sp
  190.  
  191.         pea    img_buffer(pc)        ;Start of img-data
  192.         move.l    #162*762,-(sp)        ;Number of bytes
  193.         move.w    handle(pc),-(sp)    ;File handle
  194.         move.w    #$40,-(sp)        ;Write data
  195.         trap    #1            ;Gemdos
  196.         lea    12(sp),sp
  197.         
  198.         move.w    handle(pc),-(sp)    ;File handle
  199.         move.w    #$3E,-(sp)        ;Close file
  200.         trap    #1            ;Gemdos
  201.         addq.l    #4,sp
  202.  
  203. close_window:    move.w    w_handle(pc),int_in    ;Window handle
  204.         aes    wind_close
  205.         aes    wind_delete
  206.         dc.w    $A009            ;Show mouse
  207.  
  208. abort_acc:    move.w    #2,int_in        ;Enable Mouse
  209.         aes    wind_update
  210.         movem.l    (sp)+,d0-a6        ;Restore registers
  211.         rts                ;End of program
  212.  
  213. extension:    dc.b    '\*.IMG',0,0        
  214. acc_name:    dc.b    '  Scanner 1280x762 ',0
  215. fsel_message:    dc.b    'Select file for scanned image',0
  216. alert:        dc.b    '[0][ © Lars-Erik Østerud  1991|'
  217.          dc.b    '---------------------------  |'
  218.         dc.b    ' Scan complete, what now ?]'
  219.         dc.b    '[ Scan |Save|Quit]',0
  220.         even
  221. img_header:    dc.w    $0001,$0008,$0001,$0002,$0174,$0174,1280,762
  222.         section bss
  223. w_handle:    ds.w    1    ;Window handle
  224. save_ssp:    ds.l    1    ;Old stack adress
  225. handle:        ds.w    1    ;Place for file handle
  226. msgbuff:    ds.w    16    ;Message buffer
  227. file_path:    ds.b    80    ;File path
  228. file_name:    ds.b    14    ;File name
  229. img_buffer:    ds.b    123444    ;Space for scanned image data
  230.